local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHScreenBase());
local CommonOHOH =_G.CommonOHOH
local CallBackManager = ClientOHOH.load.CallBackManager();
local BtnHelper = ClientOHOH.load.BtnHelper();
local LanguageHelper=_G.LanguageHelper 
local TweenHelper = ClientOHOH.load.TweenHelper();

function InitInsts(ui)
	ui.insts = {};
	ui.insts.root ="Frame.Frame"

	ui.insts.close ="Frame.Frame.close"
	ui.insts.title ="Frame.Frame.title"
	ui.insts.settingCell = "Frame.Frame.list.cell";

	ui.insts.soundTip = "Frame.Frame.Sound";
	ui.insts.codeTip = "Frame.Frame.Code";
	ui.insts.codeBtn = "Frame.Frame.codeBtn";
	ui.insts.codeInputText = "Frame.Frame.code.Label";
	ui.insts.codeBtnText = "Frame.Frame.codeBtn.Label";

	
end

function M.MobileSize(self)
	if _G.client.IsMobile then --是移动设备
		if self.insts.root then
			local pos= self.insts.root:GetAttribute("Position")
			local size=self.insts.root:GetAttribute("Size")
			if pos then
				self.insts.root.Position=pos
			end
			if size then
				self.insts.root.Size=size
			end
		end
	end
end

function M.new(...)
	return M(...);
end;
function M.ctor(self)
	InitInsts(self)


	M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.SettingGui"),2);
	self:MobileSize()

	
	self.insts.soundTip.Text=LanguageHelper:GetText(129)
	self.insts.codeTip.Text=LanguageHelper:GetText(20)
	self.insts.codeInputText.PlaceholderText=LanguageHelper:GetText(21) 
	self.insts.codeBtnText.Text=LanguageHelper:GetText(8) 

	-- ClientOHOH:GetPath_Loop("Btn.On",self.insts.settingCell).Text=LanguageHelper:GetText(126) 
	-- ClientOHOH:GetPath_Loop("Btn.Off",self.insts.settingCell).Text=LanguageHelper:GetText(127) 
	self.insts.title.Text=LanguageHelper:GetText(25) 

	CallBackManager:AddRbxConnect(self,self.insts.close.Activated, function()
		self:Hide()
	end);

end;

function M.GetCode(self)
	return self.insts.codeInputText.Text
end;


function M.dtor(self)
	M.super.dtor(self);
end;

function M.InitAllButtons(self)
	self:AddProcess(function()
		for _, v in pairs(self.main_inst:GetDescendants()) do
			if v:IsA("GuiButton") then
				BtnHelper:InitButton(v, nil, nil, nil, function() end);
			end;
		end;
	end);
end

function M.CreateCell(self)
	local cell=nil
	if self.usedCell then
		cell= self.insts.settingCell:Clone()
		cell.Parent=self.insts.settingCell.Parent
	else
		cell=self.insts.settingCell
		self.usedCell=true
	end

	return cell
end

function M.AddSetBtn(self, btnKey,name, state)
	assert(btnKey, "str is nil");
	local cell = self:CreateCell()
	if not cell then
		warn("\230\178\161\230\156\137\230\139\191\229\136\176UI,\229\133\139\233\154\134\230\138\165\233\148\153\239\188\129");
	end;
	cell.Txt.Text =name
	cell.Name=btnKey
	self:SetBtnSwitch2(cell.Btn, state);
	return cell.Btn;
end;

function M.SetBtnSwitch2(self, btn, state)
	if state then
		btn.text.Text=LanguageHelper:GetText(126)
		btn.BackgroundColor3=Color3.fromHex("#42cf38")
	else
		btn.text.Text=LanguageHelper:GetText(127)
		btn.BackgroundColor3=Color3.fromHex("#d55d5f")
	end
end

function M.SetBtnSwitch(self, btn, state)
	local icon = nil;
	assert(btn, "btn is nil");
	icon = btn.Icon;
	if state then
		--btn.Image = "rbxassetid://8985172014";
		btn.Icon.BackgroundColor3=Color3.new(0.321569, 1, 0.133333) --打开状态颜色
		TweenHelper:PlayTween(icon, TweenInfo.new(0.5, 1, 1), {
			Position = UDim2.new(0.57, 0, 0.5, 0) --打开状态位置
		});
		return;
	end;
	--btn.Image = "rbxassetid://8985438661";
	btn.Icon.BackgroundColor3=Color3.new(0.635294, 0.635294, 0.631373) --关闭状态颜色
	TweenHelper:PlayTween(icon, TweenInfo.new(0.5, 1, 1), {
		Position = UDim2.new(0.03, 0, 0.5, 0) --关闭状态位置
	});
end;


return M
